<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/10/12 0012
 * Time: 08:30
 */
namespace app\admin\validate;

use app\admin\model\Thumb;
use think\Request;
use think\Validate;
class Tag extends Validate
{

    protected $rule = [
        'id'          =>  'require|checkDel',
    ];

    protected $message = [
        'id.require'  =>  'id不能为空',
    ];
    //场景
    protected $scene = [
        'delete'      =>  ['id'],
    ];

    // 自定义验证规则
    //验证类目下是否有数据
    protected function checkDel(){
        $id = Request::instance()->post('id','','trim');
        if(Thumb::whereLike('tagids','%,'.$id.',%')->find()){
           return '该标签下存在图片数据，请先删除所有包含该标签的图片数据！';
        }
        return true;
    }
}